package com.boot.controller;


import com.boot.entity.Cart;
import com.boot.entity.CartList;
import com.boot.entity.R;
import com.boot.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 购物车表(Cart)表控制层
 *
 * @author makejava
 * @since 2023-07-20 18:48:25
 */
@RestController
@RequestMapping("/cart")
@CrossOrigin
public class CartController {
    /**
     * 服务对象
     */
    @Autowired
    private CartService cartService;

    /**
     * 用户端添加购物车
     * @param uid
     * @param pid
     * @param count
     * @return
     */
    @RequestMapping("/addCart")
    public R addCart(@RequestParam("uid") Integer uid, @RequestParam("pid") Integer pid, @RequestParam("count") Integer count) {
        System.out.println("用户id和商品id -->" + uid + " " + pid);
        cartService.addCart(pid, uid, count);
        return R.success("加入购物车成功！");
    }

    @RequestMapping("/showCarts")
    public R showCarts(@RequestParam("uid") Integer uid) {
        //System.out.println("uid-->" + uid);
        List<CartList> list = cartService.showCartsByUid(uid);
        return R.success(list);
    }
}

